package com.cqust.app;

import com.cqust.entity.User;
import com.cqust.mapper.UserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class App {
    public static void main(String[] args) {
        String resource = "mybatis-config.xml";
        try {
            InputStream inputStream = Resources.getResourceAsStream(resource);
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            SqlSession session=sqlSessionFactory.openSession();
            UserMapper userDao=session.getMapper(UserMapper.class);
            List<User> lst= userDao.selectAll();
            System.out.println(lst);
        }
        catch (IOException exception)
        {
            System.out.println(exception);
        }
    }
    public static void main1(String[] args) {
        String resource = "mybatis-config.xml";
        try {
            InputStream inputStream = Resources.getResourceAsStream(resource);
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            SqlSession session=sqlSessionFactory.openSession();
            User user=session.selectOne("com.cqust.mapper.UserMapper.selectById",48);
            System.out.println(user);

        }
        catch (IOException exception)
        {
            System.out.println(exception);
        }
    }
}
